/**
 * @file    removebuddy.cpp
 * @author  Siddharth Sathyam <ssathy2@gmail.com>
 * @author  Alan Ruvalcaba <aruval3@gmail.com>
 * @author  Pat LaMontagna <plamontagna@gmail.com>
 * @version 1.0
 * @section LICENSE
 *
 * This program is property of Siddharth Sathyam, Alan Ruvalcaba, Pat LaMontagna.
 *
 * @section DESCRIPTION
 *
 * The remove buddy window allows the user to remove friends from their friends list.
 */

#include "removebuddy.h"
#include "ui_removebuddy.h"

removeBuddy::removeBuddy(QWidget *parent, QString personSendingRemoveRequest) :
    QDialog(parent),
    ui(new Ui::removeBuddy)
{
    ui->setupUi(this);
    personSendingRequest = personSendingRemoveRequest;
    ui->removeButton->setDefault(true);
}

removeBuddy::~removeBuddy()
{
    delete ui;
}

void removeBuddy::handleIncomingIsValidRemoveFriendRequest(QString personToRemove, bool isValid)
{
    if(isValid)
    {
	displayMessage(personToRemove + " was successfully removed");

    }
    else if(!isValid)
    {
	displayMessage(personToRemove + " was not removed, this is an invalid request");
	this->show();
    }
}

void removeBuddy::displayMessage(QString msgToDisplay)
{
    QMessageBox* message = new QMessageBox(0);
    message->setText(msgToDisplay);
    message->setWindowTitle("Remove Buddy");
    message->setAttribute(Qt::WA_DeleteOnClose);
    message->show();
}

void removeBuddy::on_removeButton_clicked()
{
    QString userInput = ui->lineEdit->text();

    // The user name that the user is trying to add has spaces than don't let
    // the user press send, ask user to type in a number
    if(!userInput.contains(" "))
    {
	// Making sure the username isn't the person's own username and it's not blank
	if(userInput != "" && userInput != personSendingRequest)
	{
	    emit sendRemoveFriendRequest(userInput);
	}
	else
	{
	    displayMessage("Invalid User Name...Please enter a valid friend to remove");
	    this->show();
	}
    }
    else
    {
	displayMessage("Friend Names can't have spaces in them");
	this->show();
    }
}

void removeBuddy::on_cancelButton_clicked()
{
    this->close();
}
